<template>
  <div class="col">
    <ClamView :res="response" v-slot="{ data }">
      {{ data }}
    </ClamView>
  </div>
  <button @click="test">再试一次</button>
  <button @click="aggrement('1')">协议1</button>
  <button @click="aggrement('2')">协议2</button>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive } from "vue";
import ClamView from "@/components/clam_view";
import { API } from "@/http";
import { createLoading } from "@/config";

import { embraceRequest } from "@/net-http/config";
import { ApiTest } from "@/net-http/APITest";

export default defineComponent({
  name: "Home",
  components: {
    ClamView,
  },
  setup() {
    const response = reactive(
      createLoading([
        {
          name: "sych_nat_health_people_summary",
          value: "1",
        },
        {
          name: "sych_nat_fee_people_summary",
          value: "2",
        },
        {
          name: "sych_nat_warm_prompt",
          value: "3",
        },
        {
          name: "sych_nat_order_summary",
          value: "4",
        },
        {
          name: "sych_reg_questionnaire_url",
          value: "5",
        },
      ])
    );

    onMounted(() => {
      test();
    });

    interface test {
      name: string;
      age: number;
    }

    const requestTestData = () => {
      console.log("--requestTestData--");
      return new Promise<any>((resolve, reject) => {
        console.log("--getData--");
        setTimeout(() => {
          resolve({
            status: 200,
            data: {
              code: 0,
              msg: "asdasdad",
              data: {
                name: "王哈哈",
                age: 12,
              },
            },
          });
          // reject(new Error("跑个错误"));
        }, 3000);
      });
    };

    const test = () => {
      // API.getDefinedStrings().then(response.update.bind(response));

      embraceRequest<test>(requestTestData()).then((res) => {
        console.log("结果", res);
        if (res.success) {
        }
      });

      // ApiTest.login({
      //   id: 2,
      // }).then((res) => {
      //   if (res.success) {
      //     console.log(res.data);
      //   }
      //   console.log(res);
      // });
    };

    const test2 = () => {
      API.testAxios({
        id: 2,
      }).then((response: any) => {
        console.log(response);
      });
    };

    const aggrement = (id: string) => {
      API.agreementContent({
        id: id,
      }).then((res) => {
        // console.log(copyRes(res));
        console.log(res);
      });
    };

    return {
      response,
      test,
      aggrement,
      test2,
    };
  },
});
</script>
<style scoped></style>
